<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Stage extends Model
{
    protected $table='park_stage';
    protected $guarded=[];
    protected $primaryKey='StageID';
    public $timestamps=false;
    
    protected static function boot()
    {
        parent::boot();
        
        static::addGlobalScope('open', function(Builder $builder) {
            $builder->where('noOpen', 0);
        });
    }
    
    public function scopeForSell($query)
    {
        return $query->where('noOpen',0);
    }
    
    public function getPrice()
    {
        return $this->attributes['StagePrice'];
    }
    
    public function userHold()
    {
        return $this->hasMany(MyStage::class,'StageID','StageID');
    }
    
    public function getStageImgAttribute()
    {
        if(!$this->attributes['StageImg'])return '';
        return starts_with($this->attributes['StageImg'],'http') ? $this->attributes['StageImg'] : config('filesystems.disks.admin.url').$this->attributes['StageImg'];
    }
}
